<template>
  <view class="content">
    <view>
      <view class="logo">
        <u-image
          height="200rpx"
          src="/static/logo.png"
          mode="aspectFit"
        ></u-image>
      </view>
    </view>
  </view>
</template>
<script>
export default {
  onLoad: function () {
    this.weMiniLogin();
  },
  created() {},
  methods: {
    weMiniLogin() {
      let that = this;
      uni.login({
        provider: "weixin",
        success: function (loginRes) {
          if (loginRes.errMsg == "login:ok") {
            that.getToken(loginRes.code);
          }
        },
      });
    },
    setToken(token) {
      uni.setStorageSync("token", token);
      this.$u.http.setConfig({
        header: {
          Authorization: token,
        },
      });
    },
    async getToken(code) {
      let res = await this.$u.api.getToken(code);
      if (res.code == 1) {
        this.setToken(res.data.token);
        if (uni.getStorageSync("firstPage")) {
          this.$u.route({
            url: uni.getStorageSync("firstPage"),
            params: uni.getStorageSync("options"),
            type: "reLaunch",
          });
        } else {
          this.$u.route({
            url: "/pages/index/index",
            type: "reLaunch",
          });
        }
      } else {
        this.$refs.uToast.show({
          title: "登录失败，请稍后再试",
        });
        return;
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.content {
  text-align: center;
}

.logo {
  margin-top: 340rpx;
}
.logo-name {
  margin-top: 50rpx;
  margin-bottom: 190rpx;
}
</style>